<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>



    <form action="list.do">

        名称/地址 <input name="nameOrAddress" value="${query.nameOrAddress}"><br>

        省份 <select  onchange="getCity()" name="provinceId">
        <option value="">请选择</option>
        <c:forEach items="${provinceList}" var="p">
            <option    ${query.provinceId==p.id ?'selected':''}        value="${p.id}">${p.name}</option>
        </c:forEach>a
    </select><br>

        城市 <select name="cityId">
            <option value="">请选择</option>
        <c:forEach items="${cityList}" var="c">
            <option   ${query.cityId==c.id ?'selected':''}     value="${c.id}">${c.name}</option>
        </c:forEach>
    </select><br>

        <input type="submit" value="查询">   <a href="/addPage.do">添加</a>

        <table>
            <tr>
                <td>id</td>
                <td>名称</td>
                <td>地址</td>
                <td>省份</td>
                <td>城市</td>
                <td>图片</td>
            </tr>

            <c:forEach items="${pageInfo.list}" var="l">
                <tr>
                    <td>${l.id}</td>
                    <td>${l.name}</td>
                    <td>${l.address}</td>
                    <td>${l.provinceName}</td>
                    <td>${l.cityName}</td>
                    <td><img src="${l.picUrl}"></td>
                </tr>
            </c:forEach>

        </table>



    </form>


<script>

    //二级联动方案1
    // getCity(); //在页面加载完之后 自动根据省份 获取 城市列表

    function getCity() {
            let provinceId = $('[name=provinceId]').val();

            $.ajax({
                url:'getCity.do?provinceId=' + provinceId,
                success:function (res) {
                    console.log(res)
                    $('[name=cityId]').empty();
                    $('[name=cityId]').append('<option value="">请选择</option>')

                    for (let i = 0; i < res.length; i++) {
                        let id = res[i].id;
                        let name = res[i].name;
                        $('[name=cityId]').append('<option value='+id+'>'+name+'</option>')
                    }
                    // 二级联动方案1
                    <%--$('[name=cityId]').val(${query.cityId==null ?'':query.cityId})--%>

                }


            })

    }


</script>

</body>
</html>